fix: allow duplicate request content access#470
Conversation
There was a problem hiding this comment.
Pull request overview
Enables matching/verifying HttpContent multiple times (setup + verify) without consuming the underlying content stream, including additional support for .NET Framework where HttpContent can be disposed automatically.
Changes:
- Added tests to ensure setups and verifications can both read the same request content.
- Updated
HttpContentparameter matching to beHttpRequestMessage-aware and to restore stream position after reading. - Updated source generator output for
HttpClient.Send*on .NET Framework to persist request content bytes for later matching.
Reviewed changes
Copilot reviewed 10 out of 10 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| Tests/Mockolate.Tests/Web/ItExtensionsTests.IsHttpContentTests.WithStringTests.cs | Adds regression test covering setup+verify reading string content twice |
| Tests/Mockolate.Tests/Web/ItExtensionsTests.IsHttpContentTests.WithBytesTests.cs | Adds regression test covering setup+verify reading bytes content twice |
| Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PutTests.cs | Strengthens verification to also assert JSON body content |
| Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PostTests.cs | Strengthens verification to also assert JSON body content |
| Tests/Mockolate.Tests/Web/HttpClientExtensionsTests.Verify.PatchTests.cs | Strengthens verification to also assert JSON body content |
| Source/Mockolate/Web/ItExtensions.HttpContent.cs | Makes content matching request-aware and resets stream position after reads |
| Source/Mockolate/Web/IHttpRequestMessagePropertyParameter.cs | Introduces request-aware parameter interface |
| Source/Mockolate/Web/HttpClientExtensions.cs | Passes HttpRequestMessage to request-aware parameters during matching |
| Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.cs | Emits .NET Framework-specific content persistence for HttpClient.Send* |
| Source/Mockolate.SourceGenerators/Sources/Sources.ForMock.Extensions.cs | Removes prior special-casing for HttpClient.Send* setups |
|
🚀 Benchmark ResultsDetails
|
|
This is addressed in release v1.4.0. |

Enables matching/verifying
HttpContentmultiple times (setup + verify) without consuming the underlying content stream, including additional support for .NET Framework whereHttpContentcan be disposed automatically.Key Changes:
HttpContentparameter matching to beHttpRequestMessage-aware and to restore stream position after reading.HttpClient.Send*on .NET Framework to persist request content bytes for later matching.